/**************************************************************************
 *  创建者：        hualei
 *  开始时间：   2018.06.23
 *  copyright:  (C) 深圳市华友高科有限公司
 *  修改说明：  (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 *
 ***************************************************************************
 *   MOVE_FREE 自由导航指令属性编辑视窗实现
 *
 ***************************************************************************/
#include "../../programView/programview.h"
#include "movefreeinstructionview.h"
#include "ui_movefreeinstructionview.h"
#include "movefreeinstructiontrackview.h"
#include "movefreedpointview.h"
#include "../../CommunicateDelegate/communicatenormaldelegate.h"
#include "movefreevmarksettingview.h"
<<<<<<< HEAD
=======

extern FileData fileData;
>>>>>>> dev

MoveFreeInstructionView::MoveFreeInstructionView(int styleId,CommunicateNormalDelegate *communicateNormalDelegateIn, QDialog *parent) :
    QDialog(parent),
    ui(new Ui::MoveFreeInstructionView)
{
    communicateNormalDelegate=communicateNormalDelegateIn;

    ui->setupUi(this);
    initialDisplayStyle(styleId);

    ui->TrackFile_Label->hide();

    ui->VelocityRatio_slider->setMaximum(100);
    ui->VelocityRatio_slider->setMinimum(0);
    ui->VelocityRatio_LineEdit->setValidator(new QIntValidator(0,100,this));

    moveFreeInstructionTrackView = new MoveFreeInstructionTrackView;
    moveFreeInstructionTrackView->moveFreeInstructionView = this;
    moveFreeInstructionTrackView->hide();

    moveFreeDPointView = new MoveFreeDPointView(styleId);
    moveFreeDPointView->moveFreeInstructionView = this;
    moveFreeDPointView->hide();

    moveFreeMoveTypeView = new MoveFreeMoveTypeView(styleId);
    moveFreeMoveTypeView->moveFreeInstructionView = this;
    moveFreeMoveTypeView->hide();

    moveFreeVmarkSettingView = new MoveFreeVmarkSettingView(styleId);
    moveFreeVmarkSettingView->moveFreeInstructionView = this;
    moveFreeVmarkSettingView->hide();

//    ui->SeletionTrackFile_Btn->setEnabled(false);
}

void MoveFreeInstructionView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        ui->PointType_GBox->setGeometry(10,0,430,85);
        ui->DPL_TrackPoint_radioButton->setGeometry(220,55,170,25);

        ui->NavigationMode_GBox->setGeometry(10,90,430,50);

        ui->VelocityRatio_GBox->setGeometry(10,145,430,90);

        ui->note_GBox_2->setGeometry(10,240,430,55);

        ui->note_GBox->setGeometry(10,300,430,55);

        ui->forward_Btn->setGeometry(10,350,70,40);
        ui->next_Btn->setGeometry(360,355,70,40);
        break;
    default:
        break;
    }
}

void MoveFreeInstructionView::updateView()
{
    ui->DP_SinglePoint_radioButton->setChecked(false);
    ui->DPR_RegisterPoint_radioButton->setChecked(false);
    ui->DPL_TrackPoint_radioButton->setChecked(false);

    ui->WHEEL_radioButton->setChecked(false);
    ui->IMU_radioButton->setChecked(false);
    ui->LASER_radioButton->setChecked(false);

    ui->P_radioButton->setChecked(false);
    ui->N_radioButton->setChecked(false);

    ui->TrackFile_Label->hide();
    ui->TrackFileName_Label->hide();

    if(pointType == E_MOVE_FREE_POINTS_ARRY_DP)
    {
        ui->DP_SinglePointValue_lineEdit->setText(QString("%1").arg(singlePointValue));
        ui->DP_SinglePoint_radioButton->setChecked(true);
    }
    else if(pointType == E_MOVE_FREE_POINTS_ARRY_DPR)
    {
        ui->DP_SinglePointValue_lineEdit->setText(QString("%1").arg(registerPointValue));
        ui->DPR_RegisterPoint_radioButton->setChecked(true);
    }
    else if(pointType == E_MOVE_FREE_POINTS_ARRY_DPL)
    {
        ui->DPL_TrackPoint_radioButton->setChecked(true);
        ui->DP_SinglePointValue_lineEdit->setText(trackFile);
    }

    if(navigationMode == E_NAVIGATION_TYPE_WHEEL)
    {
        ui->WHEEL_radioButton->setChecked(true);
    }
    else if(navigationMode == E_NAVIGATION_TYPE_IMU)
    {
        ui->IMU_radioButton->setChecked(true);
    }
    else if(navigationMode == E_NAVIGATION_TYPE_LASER)
    {
        ui->LASER_radioButton->setChecked(true);
    }

    if(moveFreeMoveType == E_MOVE_FREE_MOVE_N)
    {
        ui->N_radioButton->setChecked(true);
    }
    else if(moveFreeMoveType == E_MOVE_FREE_MOVE_P)
    {
        ui->P_radioButton->setChecked(true);
    }

    ui->VelocityRatio_LineEdit->setText(QString("%1").arg(velocityRatio));
    ui->VelocityRatio_slider->setValue(velocityRatio);
    ui->note_lineEdit->setText(annotation);
<<<<<<< HEAD


    //更新所有页面
    moveFreeMoveTypeView->updateView();
    moveFreeVmarkSettingView->updateView();
=======
>>>>>>> dev

    //更新所有页面
    moveFreeMoveTypeView->updateView();
    moveFreeVmarkSettingView->updateView();

}

void MoveFreeInstructionView::getInput()
{
    moveFreeMoveTypeView->getInput();
    moveFreeVmarkSettingView->getInput();

    singlePointValue = ui->DP_SinglePointValue_lineEdit->text().toInt();
    registerPointValue = singlePointValue;
    trackFile=QString::number(singlePointValue);
    velocityRatio = ui->VelocityRatio_LineEdit->text().toInt();
    annotation = ui->note_lineEdit->text();
    cntValue = moveFreeMoveTypeView->cntValue;
    allowAccuracy = moveFreeMoveTypeView->allowAccuracy;
    moveFreeMoveTrajectoryType = moveFreeMoveTypeView->moveFreeMoveTrajectoryType;
}

void MoveFreeInstructionView::changeLanguage(int language)
{
    if(1 == language)
    {
        translator.load("/agvwork/AgvHmi/baseBag/hmiProject/language/moveFreeInstructionView.qm");
        qApp->installTranslator(&translator);
    }
    else
    {
        qApp->removeTranslator(&translator);
    }
    ui->retranslateUi(this);
    moveFreeDPointView->changedLanguage();
    moveFreeInstructionTrackView->changeLanguage();
    moveFreeMoveTypeView->changeLanguage();
    moveFreeVmarkSettingView->changeLanguage();

}

void MoveFreeInstructionView::on_DP_SinglePoint_radioButton_clicked()
{
    pointType = E_MOVE_FREE_POINTS_ARRY_DP;
//    ui->SeletionTrackFile_Btn->setEnabled(false);

}

void MoveFreeInstructionView::on_DPR_RegisterPoint_radioButton_clicked()
{
    pointType = E_MOVE_FREE_POINTS_ARRY_DPR;
//    ui->SeletionTrackFile_Btn->setEnabled(false);
}

void MoveFreeInstructionView::on_DPL_TrackPoint_radioButton_clicked()
{
    pointType = E_MOVE_FREE_POINTS_ARRY_DPL;
//    ui->SeletionTrackFile_Btn->setEnabled(true);
}

void MoveFreeInstructionView::on_forward_Btn_clicked()
{
    this->close();
    programView->instructionListFlag = 0;
    programView->editInstructionViewShowOrHide();
}

void MoveFreeInstructionView::finishedEditInstruction_slot()
{

    getInput();
    emit finishEditInstructionSignal();
    emit saveInstructionSignal(instruction);
}

void MoveFreeInstructionView::on_clearNote_Btn_clicked()
{
    ui->note_lineEdit->clear();
    emit clearNoteSignal();
}

void MoveFreeInstructionView::on_WHEEL_radioButton_clicked()
{
    navigationMode = E_NAVIGATION_TYPE_WHEEL;
}

void MoveFreeInstructionView::on_IMU_radioButton_clicked()
{
    navigationMode = E_NAVIGATION_TYPE_IMU;
}

void MoveFreeInstructionView::on_LASER_radioButton_clicked()
{
    navigationMode = E_NAVIGATION_TYPE_LASER;
}

void MoveFreeInstructionView::on_VelocityRatio_slider_valueChanged(int value)
{
    velocityRatio =value;
    ui->VelocityRatio_LineEdit->setText(QString("%1").arg(value));
}

void MoveFreeInstructionView::on_VelocityRatio_slider_sliderMoved(int position)
{
    velocityRatio = position;
    ui->VelocityRatio_LineEdit->setText(QString("%1").arg(position));
}

//void MoveFreeInstructionView::on_SeletionTrackFile_Btn_clicked()
//{
//    moveFreeInstructionTrackView->show();
//    moveFreeInstructionTrackView->initView();
//}

void MoveFreeInstructionView::on_EditPoint_Btn_clicked()
{
    singlePointValue = ui->DP_SinglePointValue_lineEdit->text().toInt();
    this->close();
    moveFreeDPointView->show();
    // 如果点位索引值容器中存在,就使用容器缓存的点位数据
    // 如果不存在就初始化一个点位
    if(fileData.vehicleDPointList.keys().contains(singlePointValue))
    {
       moveFreeDPointView->dPointTemp = fileData.vehicleDPointList.value(singlePointValue);
<<<<<<< HEAD
       qDebug() << "Current Edit DPoint Index :" << moveFreeDPointView->dPointTemp.dpIndex;
       qDebug() << "Current Edit DPoint MapName :" << QString::fromStdString(moveFreeDPointView->dPointTemp.mapName);
       qDebug() << "Current Edit DPoint X :" << moveFreeDPointView->dPointTemp.posX;
       qDebug() << "Current Edit DPoint Y :" << moveFreeDPointView->dPointTemp.posY;
       qDebug() << "Current Edit DPoint R :" << moveFreeDPointView->dPointTemp.posR;

=======
       moveFreeDPointView->testDPoint = moveFreeDPointView->dPointTemp;
       moveFreeDPointView->testDPoint.posX = moveFreeDPointView->testDPoint.posX/1000.000;
       moveFreeDPointView->testDPoint.posY = moveFreeDPointView->testDPoint.posY/1000.000;
       moveFreeDPointView->testDPoint.mapName = moveFreeDPointView->dPointTemp.mapName;

       QString pointType;
       if(moveFreeDPointView->dPointTemp.pointType == EM_MOVE_FREE_DP)
       {
            pointType = tr("DP");
       }
       else if(moveFreeDPointView->dPointTemp.pointType == EM_MOVE_FREE_QR)
       {
             pointType = tr("QR");
       }
       else
       {
            pointType = tr("VMark");
       }

       qDebug() << "Current Edit Point Type : " << pointType;
       qDebug() << "Current Edit Point Index :" << moveFreeDPointView->dPointTemp.dpIndex;
       qDebug() << "Current Edit Point MapName :" << QString::fromStdString(moveFreeDPointView->dPointTemp.mapName);
       qDebug() << "Current Edit Point X :" << moveFreeDPointView->dPointTemp.posX;
       qDebug() << "Current Edit Point Y :" << moveFreeDPointView->dPointTemp.posY;
       qDebug() << "Current Edit Point R :" << moveFreeDPointView->dPointTemp.posR;
>>>>>>> dev
    }
    else
    {
        /*************** 测试使用　******************/
        // 初始点位
        std::string mapName;
        communicateNormalDelegate->getCurrentMapName(mapName);
        moveFreeDPointView->dPointTemp.mapName = mapName;
        moveFreeDPointView->dPointTemp.posX = 0.000;
        moveFreeDPointView->dPointTemp.posY = 0.000;
        moveFreeDPointView->dPointTemp.posR = 0.000;
        moveFreeDPointView->dPointTemp.dpIndex = singlePointValue;
    }
    moveFreeDPointView->updateView();
}

//void MoveFreeInstructionView::on_recordPoint_Btn_clicked()
//{
//    emit recordDPointSignal(E_RECORD_CURRENT_POINT);
//}

void MoveFreeInstructionView::on_moveToPoint_Btn_clicked()
{
    int dpointNum = fileData.vehicleDPointList.size();
    emit moveToDPointSignal(dpointNum);
}

void MoveFreeInstructionView::on_VelocityRatio_LineEdit_textChanged(const QString &arg1)
{
    int velocityRatioTemp = arg1.toInt();
    ui->VelocityRatio_slider->setSliderPosition(velocityRatioTemp);
}

void MoveFreeInstructionView::on_P_radioButton_clicked()
{
    moveFreeMoveType = E_MOVE_FREE_MOVE_P;
}

void MoveFreeInstructionView::on_N_radioButton_clicked()
{
    moveFreeMoveType = E_MOVE_FREE_MOVE_N;
}

void MoveFreeInstructionView::on_MovePmtSet_Btn_clicked()
{
    this->close();
    moveFreeMoveTypeView->show();
}

void MoveFreeInstructionView::on_next_Btn_clicked()
{
    this->close();
    moveFreeVmarkSettingView->show();
}
